using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class EmployeeMap : EntityTypeConfiguration<Employee>
    {
        public EmployeeMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            this.Property(t => t.Name)
                .HasMaxLength(100);

            this.Property(t => t.Function)
                .HasMaxLength(250);

            this.Property(t => t.Expertise)
                .HasMaxLength(250);

            this.Property(t => t.Description)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("Employees");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.Function).HasColumnName("Function");
            this.Property(t => t.Expertise).HasColumnName("Expertise");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.LevelID).HasColumnName("LevelID");
            this.Property(t => t.UnitID).HasColumnName("UnitID");

            // Relationships
            this.HasOptional(t => t.WorkerLevel)
                .WithMany(t => t.Employees)
                .HasForeignKey(d => d.LevelID);
            this.HasOptional(t => t.Unit)
                .WithMany(t => t.Employees)
                .HasForeignKey(d => d.UnitID);

        }
    }
}
